package com.example.farmeri.presenter.strategy;

import com.example.farmeri.http.API;
import com.example.farmeri.pojo.Role;
import com.example.farmeri.presenter.base.BasePresenter;
import com.example.farmeri.tools.ResponseUtils;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class ViewStrategyPresenter extends BasePresenter<IViewStrategyContract> {
    protected final String TAG = this.getClass().getSimpleName();

    public ViewStrategyPresenter(IViewStrategyContract view) {
        super(view);
    }

    public void getRole(String id) {
        getRetrofit()
                .create(API.class)
                .getRole(id)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResponseUtils<Role>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull ResponseUtils<Role> roleResponseUtils) {
                        if (roleResponseUtils.getCode() == 200){
                            getView().onRoleDataResult(roleResponseUtils.getData());
                        }else {

                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
